#include <iostream>
#include <memory>
#include <string>

// 工厂模式
// 每个工厂只生产一种产品
// 增加一种产品，就新增一个工厂
class Fruit
{
public:
    Fruit() {}
    virtual void show() = 0;
};

class Apple : public Fruit
{
public:
    Apple() {}
    virtual void show()
    {
        std::cout << "我是⼀个苹果" << std::endl;
    }
};

class Banana : public Fruit
{
public:
    Banana() {}
    virtual void show()
    {
        std::cout << "我是⼀个⾹蕉" << std::endl;
    }
};

// 工厂类
class FruitFactory
{
public:
    virtual std::shared_ptr<Fruit> create() = 0;
};
// 一个工厂只生产一种产品
class AppleFactory : public FruitFactory
{
public:
    std::shared_ptr<Fruit> create() override
    {
        return std::make_shared<Apple>();
    }
};

class BananaFactory : public FruitFactory
{
public:
    std::shared_ptr<Fruit> create() override
    {
        return std::make_shared<Banana>();
    }
};
int main()
{
    std::shared_ptr<FruitFactory> fatcory(new AppleFactory());
    std::shared_ptr<Fruit> fruit=fatcory->create();
    fruit->show();

    fatcory.reset(new BananaFactory());
    fruit=fatcory->create();
    fruit->show();
    return 0;
}